from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime

class ScheduleIn(BaseModel):
    """班次创建/更新请求模型"""
    departure: str = Field(..., min_length=2, example='北京')
    destination: str = Field(..., min_length=2, example='上海')
    departure_time: datetime
    arrival_time: datetime
    seats_total: int = Field(..., gt=0, example=50)
    price: float = Field(..., gt=0, example=299.0)

    
    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "departure": "北京",
                "destination": "上海",
                "departure_time": "2024-03-25T08:00:00",
                "arrival_time": "2024-03-25T12:00:00",
                "seats_total": 50,
                "price": 299.0
            }
        }
    )

class ScheduleOut(ScheduleIn):
    """班次详情响应模型"""
    id: int
    seats_available: int
    created_by: str

    model_config = ConfigDict(
        from_attributes=True  
    )